package com.ljf.config.domain.validator;

import com.ljf.common.domain.validator.BasisValidator;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.utils.EnumUtil;
import com.ljf.config.domain.repository.ConfigDatRecordSymbolRepository;
import com.ljf.config.dto.command.ConfigDatRecordSymbolCommand;
import com.ljf.config.dto.query.ConfigDatRecordSymbolQuery;
import com.ljf.config.enums.ConfigDatRecordSymbolTypeEnum;
import com.ljf.config.model.ConfigDatRecordSymbol;
import com.ljf.config.vo.ConfigDatRecordSymbolVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 记录标签配置  业务校验
 *
 * @author LJF
 * @since 2025-02-01
 */
@Component
@AllArgsConstructor
public class ConfigDatRecordSymbolValidator extends BasisValidator<ConfigDatRecordSymbolQuery, ConfigDatRecordSymbolCommand, ConfigDatRecordSymbolVO, ConfigDatRecordSymbol, ConfigDatRecordSymbolRepository> {

    @Override
    public void checkAdd(ConfigDatRecordSymbolCommand command) throws ServiceException {
        super.checkAdd(command);
        if (!EnumUtil.checkCode(command.getType(), ConfigDatRecordSymbolTypeEnum.values())) {
            throw new ServiceException("记录标签配置新增校验异常:类型不存在");
        }
    }

    @Override
    public void checkEdit(ConfigDatRecordSymbolCommand command) throws ServiceException {
        super.checkEdit(command);
        command.setType(null);
    }

}
